<%
  next_stages = @stage.pipeline_next_stages.to_a.presence
  previous_stages = @stage.pipeline_previous_stages.to_a.presence
%>

<% if next_stages || previous_stages %>
  <h2>Pipelining</h2>

  <% if previous_stages %>
    <div>
      The following stages will trigger this stage on completion:
      <ul>
        <% previous_stages.each do |stage| %>
          <li><%= link_to stage.name, [@project, stage] %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <% if next_stages %>
    <div>
      After this stage finishes deploying it will deploy to:
      <ul>
        <% next_stages.each do |stage| %>
          <li>
            <%= link_to stage.name, [@project, stage] %>
            <% if last_deploy = stage.last_deploy %>
              Last Deploy: <%= render_time last_deploy.start_time %> <%= status_badge last_deploy.status %>
            <% end %>
          </li>
        <% end %>
      </ul>
    </div>
  <% end %>
<% end %>
